
dict1={"name":"suki",'age':20}
dict_iter = dict1.__iter__()   # 创建了一个迭代器
# 结合next进行访问下一次内容
print(dict_iter.__next__())
print(dict_iter.__next__())

str_obj = "abcdefg"  #obj对象的意思
str_iter = str_obj.__iter__()
print(next(str_iter))
print(next(str_iter))
print(next(str_iter))
print(next(str_iter))

dic1 = {"name":"zhangsan",'age':19}
print(next(dic1.__iter__()))
print(next(dic1.__iter__()))
print(next(dic1.__iter__()))
print(next(dic1.__iter__()))
print(next(dic1.__iter__()))

def num():
    a = 0
    while True:
        yield a

        a +=1
a = num()
print(next(a))
print(next(a))
print(next(a))

"""
生成器也是迭代器的一种，但是它只能够迭代一次
yield相当于一个return，会有返回值
下次再调用函数的时候，会从下向上执行代码块
"""














